<template>
	<view class="pay">
		<view class="payorder">
			<view class="payNumber">
				订单号:{{outTradeNo}}
			</view>
			<view class="payPrice">
				<text>¥</text>{{totalAmount}}
			</view>
			<view class="payTime">
				<!-- 最迟支付时间:{{payinfo.end_time}} -->
			</view>
		</view>
		<view class="payType">
			<view class="payTypeTitle">
				请选择支付方式
			</view>
				<radio-group @change="radioChange" >
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/pay/alipay.png" class="payicon"></image>支付宝支付
					</view>
					<radio color="#01c2fa" value="1" checked=""></radio>
				</view>
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/pay/wxpay.png"  class="payicon"></image>微信支付
					</view>
					<radio color="#01c2fa" value="2"  :disabled="true"></radio>
				</view>
			</radio-group>
		
		</view>
		<view class="payButton" @click="pay">
			确定支付
		</view>
		
		<!-- 添加支付表单区域 -->
		<div id="divform"></div>
	</view>
	
</template>

<script>
	var app =  getApp();
	export default{
		data(){
			return{
				paytype:1,
				payForm:'',//初始化支付表单
				totalAmount:200,//初始化总支付金额
				outTradeNo:'2012121909021',//初始化主订单号
			}
		},
		onLoad(option) {
			let {outTradeNo,totalAmount}  = option;
			this.outTradeNo = outTradeNo;
			this.totalAmount = totalAmount
		},
		methods:{
			// 切换支付方式
			radioChange(){},
			async pay(){
				// 支付功能
				// api： alipay
				// params：  outTradeNo totalAmount  type =1
				// header
				// post
				var option = {
					url:"alipay",
					data:{
						outTradeNo:this.outTradeNo,
						totalAmount:this.totalAmount,
						type:1
					},
					header:app.globalData.header,
					method:"post"
				}
				
				var  res =  await this.$http(option);
				console.log(res)
				if(res.data.code == 200){
					// 请求成功
					let  form =  res.data.list; //获取支付表单
					let divForm =  document.getElementById("divform");
					divForm.innerHTML = form;
					document.forms[0].submit()
				}else if(res.data.code ==403){
					// 过期了
					this.$tips.restore(this, app);
					uni.showModal({
						title: res.data.msg,
						content: "您确定重新登录么？",
						success(result) {
							// console.log(res)
							if (result.confirm) {
								// 同意登录
								uni.reLaunch({
									url: "../user/user"
								})
							} else {
								// 不同意登录
								uni.reLaunch({
									url: "../index/index"
								})
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	/* 引入样式 */
	@import '@/static/css/pay.css';
</style>
